﻿using Com.Lancetinc.Evs.Services;
using System;
using System.Windows;

namespace Com.Lancetinc.Evs.Controls
{
    /// <summary>
    /// 实验详情页面，视频播放+截图
    /// </summary>
    public partial class ExperVideo2ImageUserControl
    {
        private ExperInfo mExper;

        public event EventHandler<bool> OnFullScreenChanged;

        public void SetExper(ExperInfo exper)
        {
            mExper = exper;
            CtrlVideoPlay.SetExper(exper);
        }

        public ExperVideo2ImageUserControl()
        {
            InitializeComponent();
        }

        private bool IsCapturedImageCtrlVisible
        {
            get => GridCapturedImage.Visibility == Visibility.Visible;
            set => GridCapturedImage.Visibility = value ? Visibility.Visible : Visibility.Collapsed;
        }

        private void CtrlCapturedImage_OnCloseClicked(object sender, EventArgs e)
        {
            IsCapturedImageCtrlVisible = false;
        }

        /// <summary>
        /// 显示已截屏
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CtrlVideoPlay_OnRequireShowCapturedScreen(object sender, EventArgs e)
        {
            if (IsCapturedImageCtrlVisible)
            {
                IsCapturedImageCtrlVisible = false;
                return;
            }

            // 显示已截屏的图片
            IsCapturedImageCtrlVisible = true;
            CtrlCapturedImage.SetExper(mExper);
        }

        /// <summary>
        /// 全屏切换
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="isFullScreen"></param>
        private void CtrlVideoPlay_OnFullScreenChanged(object sender, bool isFullScreen)
        {
            if (isFullScreen && IsCapturedImageCtrlVisible)
                IsCapturedImageCtrlVisible = false;

            OnFullScreenChanged?.Invoke(this, isFullScreen);
        }

        /// <summary>
        /// 截图成功
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="imageName"></param>
        private void CtrlVideoPlay_OnVideoImageCaptured(object sender, string imageName)
        {
            // 显示已截屏的图片
            IsCapturedImageCtrlVisible = true;
            CtrlCapturedImage.SetExper(mExper);
            CtrlCapturedImage.ShowImage(imageName);
        }
    }
}
